<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="fn1()">获取用户请求</button>
    <button onclick="fn2()">带参请求</button>
    <button onclick="fn3()">post带参</button>
    <button onclick="fn4()">post无参</button>
    <button onclick="fn5()">jquery get</button>
    <button onclick="fn6()">jquery get带参</button>
    <button onclick="fn7()">jquery post</button>
    <button onclick="fn8()">jquery post带参</button>
    <div id="showtime"></div>
</body>
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script>
    function fn1(){
   
        var xhr=null
        if(window.XMLHttpRequest){
            xhr = new XMLHttpRequest()
        }else {
            xhr = new ActiveXObject('Microsoft.XMLHttp')
        }

        xhr.open('get','http://127.0.0.1:3000/gettime',true)
        xhr.send()
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status ==200){
                var data = xhr.responseText
                console.log(data);
                document.querySelector('#showtime').innerHTML=data
            }
        }
    }
    function fn2(){
       
        var xhr=null
        if(window.XMLHttpRequest){
            xhr = new XMLHttpRequest()
        }else {
            xhr = new ActiveXObject('Microsoft.XMLHttp')
        }

        xhr.open('get','http://127.0.0.1:3000/login?name=李四&pwd=123',true)
        xhr.send()
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status ==200){
                var data = xhr.responseText
                console.log(data);
                document.querySelector('#showtime').innerHTML=data
            }
        }
    }
    function fn3(){
       
        var xhr=null
        if(window.XMLHttpRequest){
            xhr = new XMLHttpRequest()
        }else {
            xhr = new ActiveXObject('Microsoft.XMLHttp')
        }
        let user = {
            name:'李四',
            pwd:'123456'
        }
        xhr.open('post','http://127.0.0.1:3000/login',true)
        xhr.setRequestHeader('Content-Type','application/json')
        xhr.send(JSON.stringify(user))
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status ==200){
                var data = xhr.responseText
                console.log(data);
                document.querySelector('#showtime').innerHTML=data
            }
        }
    }
    function fn4(){

       
        var xhr=null
        if(window.XMLHttpRequest){
            xhr = new XMLHttpRequest()
        }else {
            xhr = new ActiveXObject('Microsoft.XMLHttp')
        }
        
        xhr.open('post','http://127.0.0.1:3000/gettime',true)
        // xhr.setRequestHeader('Content-Type','application/json')
        xhr.send()
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status ==200){
                var data = xhr.responseText
                console.log(data);
                document.querySelector('#showtime').innerHTML=data
            }
        }
    }
    function fn5(){
        $.ajax({
            type: "get",
            url: "http://127.0.0.1:3000/gettime",
           
            success: function (response) {
                console.log(response);
                document.querySelector('#showtime').innerHTML=response
            }
        });
    }
    function fn6(){
        $.ajax({
            type: "get",
            url: "http://127.0.0.1:3000/login?name=王五&pwd=123",
            
            success: function (response) {
                console.log(response);
                document.querySelector('#showtime').innerHTML=response
            }
        });
    }
    function fn7(){
        $.ajax({
            type: "post",
            url: "http://127.0.0.1:3000/gettime",
            
            success: function (response) {
                console.log(response);
                document.querySelector('#showtime').innerHTML=response
            }
        });
    }
    function fn8(){
        $.ajax({
            type: "post",
            url: "http://127.0.0.1:3000/login",
            data:{
                name:'哈哈',
                pwd:'1234'
            },
            success: function (response) {
                console.log(response);
                document.querySelector('#showtime').innerHTML=response
            }
        });
    }



















</script>
</html>